package com.example.xd.mvp_project.view.fragment;

import android.support.v4.app.Fragment;

import com.example.xd.mvp_project.base.BaseFragment;

import java.util.HashMap;
import java.util.Map;

/**
 * @auther XuDan on 2018/9/28.
 */
public class FragmentFactory {
    /**
     * 私有构造，单例
     */
    private FragmentFactory() {

    }

    //存储创建的Fragment
    private static Map<Class, BaseFragment> mFragmentMap = new HashMap<>();

    public static synchronized BaseFragment getInstance(Class<? extends BaseFragment> clazz) {
        BaseFragment fragment = mFragmentMap.get(clazz);
        if (fragment == null) {
            try {
                fragment = clazz.newInstance();
                mFragmentMap.put(clazz, fragment);
            } catch (Exception e) {

            }
        }
        return fragment;
    }
}
